package com.Offer;

import java.util.ArrayList;

/*
    面试题59：队列的最大值
    给定一个数组和滑动窗口的大小，请找出所有滑动窗口里的最大值
    例如数组{2,3,4,2,6,2,5,1}和数字3，所以有6个滑动窗口，窗口里最大值为{4,4,6,6,6,5}
 */
public class demo59 {

    public static void main(String[] args) {
        int[] input = {2,3,4,2,6,2,5,1};
        ArrayList<Integer> list = maxInWindows(input, 3);
        list.forEach(System.out::println);
    }

    public static ArrayList<Integer> maxInWindows(int[] num,int size){
        if (num == null || size < 1 || num.length < size)
            return null;
        ArrayList<Integer> list = new ArrayList<>();
        int length = num.length-size+1;
        for (int i = 0; i < length; i++) {
            int current = size + i;
            int max = num[i];
            for(int j = i;j < current;j++){
                if (max < num[j]){
                    max = num[j];
                }
            }
            list.add(max);
        }
        return list;
    }
}
